package newspapers;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import javax.jms.JMSException;

import model.Newspaper;

/**
 * Example of newspaper: The Sun.
 */
public class TheSun extends Newspaper {

    /**
     * Constructor.
     *
     * @param name  name of the newspaper
     * @param username  username to use to connect to the broker
     * @param password  password to use to connect to the broker
     * @param topicPrefix  prefix in the topics of the newspaper
     * @param topics  list of topics to publish to
     */
    public TheSun(final String name, final String username,
                  final String password, final String topicPrefix,
                  final Set<String> topics) {
        super(name, username, password, topicPrefix, topics);
    }

    /**
     * Creates The Sun and publishes a few messages.
     *
     * @param args  array of arguments from the command line (unused)
     */
    public static void main(String[] args) {
        //decide what topics the newspaper will publish to
        Set<String> topics = new HashSet<String>();
        topics.add("sun.sport");
        topics.add("sun.music");
        topics.add("sun.arts");

        //create The Sun
        TheSun theSun = new TheSun("The Sun", "guest", "guest", "sun", topics);

        try {
        	
	        //publish some messages, with properties
	        HashMap<String, String> properties3 = new HashMap<String, String>();
	        properties3.put("header", "news1 from sun-sport");
	        theSun.publishMessage("sun.sport", "Message about sports from "
	                + theSun.getName() + " without properties", properties3);
	        HashMap<String, String> properties = new HashMap<String, String>();
	        properties.put("author", "John Smith");
	        properties.put("date", "November 09");
	        properties.put("music", "rock");
	        properties.put("header", "news1 from sun-music");
	        theSun.publishMessage("sun.music", "Message about music from "
	                + theSun.getName() + " with properties", properties);
	        HashMap<String, String> properties7 = new HashMap<String, String>();
	        properties7.put("author", "Paul Taylor");
	        properties7.put("date", "November 09");
	        properties7.put("music", "rock");
	        properties7.put("header", "news2 from sun-music");
	        theSun.publishMessage("sun.music", "Another message about music from "
	                + theSun.getName() + " with properties", properties7);
	        HashMap<String, String> properties2 = new HashMap<String, String>();
	        properties2.put("header", "news1 from sun-arts");
	        theSun.publishMessage("sun.arts", "Message about arts from "
	                + theSun.getName() + " without properties", properties2);

            //close connections
            theSun.closeConnections();
            
        } catch (JMSException e) {
            //connections already closed?
        }
    }

}
